<?php
// 本类由系统自动生成，仅供测试用途
class LoginAction extends Action {
	public function login(){
		$this->display();
	}
	public function register(){
		$this->display();
	}
	public function checkuser(){
		$arr['email'] = $_POST['email'];
		$arr['pwd'] = $_POST['pwd'];
		
		$user = M("users");
		
		$res = $user->where($arr)->find();
		$userId=$res['id'];
		$email = $res['email'];
//		print_r($res);die;
		if($res){
			$info['info'] = "登录成功";
			$info['status'] = 1;
			session("uid",$userId);
			session("email",$email);
		}else{
			$info['info'] = "登录失败";
			$info['status'] = 2;
		}
		$this->ajaxReturn($info);
	}
	
	//退出登入
	public function logout(){
		session('uid',null);
		session('email',null);
		$this->success('退出成功','__GROUP__/Index/index');
	}
	
	
	public function adduser(){
		$email = $_POST['email'];
		$verifyEmail = "/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/";
		if(preg_match($verifyEmail, $email)){
		    $arr['email'] = $_POST['email'];
			$arr['pwd'] = $_POST['pwd'];
			
			$user = M('users');
			$res = $user->add($arr);
			if($res){
				$info['info']= "注册成功";
				$info['status']=1;
			}else{
				$info['info']= "注册失败";
				$info['status']=2;
			}
		}else{
		    $info['info']= "请输入正确的邮箱地址";
			$info['status']=3;
		}
		$this->ajaxReturn($info);
	}
	//-------测试取session
	public function getSession(){
		echo $_SESSION['uid'];
	}
	
}
